﻿using SharedModule;
using System.Text.Json;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;

namespace 接收日志
{
    /// <summary>
    /// 订阅了EventLogData;应该是再这里可以绑定EventLogData和ReceiveEventLogs之间的关系
    /// </summary>
    public class ReceiveEventLogHandler : IDistributedEventHandler<EventLogData>, ITransientDependency
    {
        //private readonly IDistributedEventBus _distributedEventBus;

        public ReceiveEventLogHandler(IDistributedEventBus distributedEventBus)
        {
            //_distributedEventBus = distributedEventBus;
        }

        public async Task HandleEventAsync(EventLogData eventData)
        {
            try
            {
                // 处理事件逻辑...
                Console.WriteLine("************************ 订阅到日志信息 ****************************");
                Console.WriteLine(JsonSerializer.Serialize(eventData.EventCreatePostDto));
                Console.WriteLine("*************************开始记录日志****************************");
                //Console.WriteLine();
                Console.WriteLine("*************************记录日志成功****************************");

                // 手动确认事件
                // 如果事件处理程序成功执行(没有抛出任何异常),它将向消息代理发送确认(ACK).队列里消息就会清除
                // 模拟异常，测试会不会继续发
                //throw new Exception("异常信息！");
            }
            catch (Exception ex)
            {
                // 处理异常情况
                await Console.Out.WriteLineAsync(ex.ToString());
            }
        }
    }
}